package org.jeecg.glr.service.impl;

import org.jeecg.common.util.SysUtil;
import org.jeecg.glr.entity.GlrSensorSet;
import org.jeecg.glr.mapper.GlrSensorSetMapper;
import org.jeecg.glr.service.IGlrSensorSetService;
import org.jeecg.glr.util.GLRConstant;
import org.jeecg.glr.util.StringUtil;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;

/**
 * @Description: 参数设置
 * @Author: jeecg-boot
 * @Date:   2020-07-30
 * @Version: V1.0
 */
@Service
public class GlrSensorSetServiceImpl extends ServiceImpl<GlrSensorSetMapper, GlrSensorSet> implements IGlrSensorSetService {

    @Resource GlrSensorSetMapper glrSensorSetMapper;


    @Override
    public GlrSensorSet getSenSorSetByStatus() {
        return glrSensorSetMapper.getSenSorSetByStatus();
    }

    @Override
    public void startUsing(GlrSensorSet glrSensorSet) {
        if(StringUtil.isNotEmpty(glrSensorSet.getIds())){
            String[] ids=glrSensorSet.getIds().split(",");
            for (String id :
                    ids) {
                if(GLRConstant.YN_Y.equals(glrSensorSet.getStatus())){
                    String sql="update glr_sensor_set set status='"+GLRConstant.YN_N+"' where id <> '"+id+"' and sys_company_code='"+ SysUtil.getUserInfo().getSysCompanyCode() +"'";
                    String sql_2="update glr_sensor_set set status='"+GLRConstant.YN_Y+"' where id = '"+id+"' and sys_company_code='"+ SysUtil.getUserInfo().getSysCompanyCode() +"'";
                    glrSensorSetMapper.startUsing(sql);
                    glrSensorSetMapper.startUsing(sql_2);
                }else{
                    String sql_2="update glr_sensor_set set status='"+GLRConstant.YN_N+"' where id = '"+id+"'";
                    glrSensorSetMapper.startUsing(sql_2);
                }
            }
        }
    }
}
